
//这是拦截器
import axios from "axios";
//创建一个单例(实例)
const instance = axios.create({
  baseURL: "/wyy",
  timeout: 4000,
});

//拦截器-请求拦截
instance.interceptors.request.use(
  (config) => {
    //部分接口需要拿到token
    // let token = localStorage.getItem("usertoken");
    // if (token) {
    //   config.headers['authorization']=token;
    // }

    return config;
  },
  (err) => {
    return Promise.reject(err);
  }
);

//拦截器-响应拦截
instance.interceptors.response.use(res=>{
  return res;
},err=>{
  console.log("err",err);
  let msg="服务器出错啦";
  return Promise.reject(msg)
})

//整体导出
export default instance;